<template>
  <div class="app">
    <uploadApp :show="show" v-if="false" />
    <router-view />
    <!-- 登录注册 弹窗 -->
    <!-- <modelpopu
      :modelshow="main.loginLayer"
      ref="popureter"
      @cloeselogin="cloeselogin"
    ></modelpopu> -->
    <notify
      :notifyShow="main.notifyShow"
      ref="notifyRef"
      @notifyClose="notifyClose"
    ></notify>
    <pc-login />
    <pc-register />
    <pc-forget />
  </div>
</template>

<script setup>
import { ref, nextTick, onMounted, onUnmounted } from "vue";
import { canScroll } from "@/utils/scrollload";
import modelpopu from "@/components/login/modelpopu.vue";
import uploadApp from "@/components/uploadApp/index.vue";
import { useBoolean } from "./hooks/useBoolean";
import { mainAct } from "@/store/activeda";
import { useRoute } from "vue-router";
import { url2obj } from "./utils/url2obj";
import { ElMessage } from "element-plus";
import { init } from "@/api/user.js";

import pcLogin from "./components/login/pc-login.vue";
import pcRegister from "./components/login/pc-register.vue";
import pcForget from "./components/login/pc-forget.vue";
import { useDeviceType } from "./hooks/useDeviceType";
const main = mainAct();

const popureter = ref();

const notifyRef = ref();

const notifyClose = () => {
  main.notifyClose();
};
const { boolean: show, setTrue, setFalse } = useBoolean();

// 判断是否是宽屏设备
function isWideScreen() {
  return window.innerWidth > 1200; // 判断宽屏设备
}

// 根据环境条件执行逻辑
function updateDownloadVisibility() {
  // const platform = url2obj(window.location.href).platform;
  const platform = window.location.href;
  const regex = /platform=apk/;
  if (regex.test(platform)) {
    console.log("字符串中包含 'platform=apk'");
  } else {
    console.log("字符串中不包含 'platform=apk'");
  }
  console.log("platform", platform);

  // 判断平台和设备环境显示下载提示
  // if (platform === "apk") {
  if (regex.test(platform)) {
    console.log("在 APK 中，不提示下载");
    setFalse(); // 如果是 APK 环境，则不显示下载提示
  } else if (isWideScreen()) {
    console.log("在宽屏设备中，不提示下载");
    setFalse(); // 如果是宽屏设备（PC端超过1200px），则不显示下载提示
  } else {
    console.log("在其他设备中，显示下载提示");
    setTrue(); // 其他设备（如 H5 或小屏设备）显示下载提示
  }
}
const handleGlobalClick = event => {
  const className = event.target.className || "无类名";
  ElMessage.success("点击的元素类名：" + className);
};
onMounted(async () => {
  let res = await init();
  main.static_base_url = res.data?.static_base_url;
  main.currency = res.data?.currency;
  main.lang_support_list = res.data?.lang_support_list;
  main.business_list = res.data?.business_list;
  main.customerService = res.data?.customer_service;
  main.timeZone = res.data?.time_zone?.zone;
  main.timeZoneObject = res.data?.time_zone;
  console.log("main.timeZone", main.timeZone);

  updateDownloadVisibility(); // 页面加载时检查是否显示下载提示
  // document.addEventListener("click", handleGlobalClick);
  // 监听窗口大小变化，更新显示状态
  window.addEventListener("resize", updateDownloadVisibility);
});

const timer = ref("");
useDeviceType();

onUnmounted(() => {
  // 组件销毁时移除事件监听器
  window.removeEventListener("resize", updateDownloadVisibility);
});
</script>

<style scoped>
.app {
  width: 100%;
  height: 100%;
}
</style>
